﻿using AutoMapper;
using Common.Communal;
using ERP.Domain.Processs;
using ERP.Domain.Workorders;
using MediatR;
using Sell.Api.Write.Application.Command.WorkordersCommand;
using Sell.Services.Pro;
using Sell.Services.Workorders;

namespace Sell.Api.Write.Application.CommandHandlers.WorkordersCommandHandlers
{
    public class WorkorderAddCommandHandlers : IRequestHandler<WorkorderAddCommand, ApiResult<int>>
    {
        public IMapper Mapper { get; }
        public IWorkorderServices services { get; }
        public WorkorderAddCommandHandlers(IMapper _Mapper, IWorkorderServices _services)
        {
            Mapper = _Mapper;
            services = _services;
        }
        public async Task<ApiResult<int>> Handle(WorkorderAddCommand request, CancellationToken cancellationToken)
        {
            var list = Mapper.Map<Workorder>(request);
            return await services.AddWorkorder(list);
        }
    }
}
